package com.quan.junit.easypoi;

import java.io.File;
import java.io.FileOutputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.poi.ss.usermodel.Workbook;
import org.junit.Test;

import com.quan.common.utils.DateUtils;
import com.quan.system.common.dto.excel.EmpYearHolidayExportExcel;

import cn.afterturn.easypoi.excel.ExcelExportUtil;
import cn.afterturn.easypoi.excel.entity.TemplateExportParams;

public class ExportEmpHoliday {

	@Test
	public void test() {
		try {
			List<EmpYearHolidayExportExcel> objList = new ArrayList<EmpYearHolidayExportExcel>();
			for(int i=0; i<10; i++) {
				EmpYearHolidayExportExcel ee = new EmpYearHolidayExportExcel();
				ee.setOrder(i+1);
				ee.setName("Hello"+ i);
				objList.add(ee);
			}

			TemplateExportParams params = new TemplateExportParams("export/年假发放单模板.xlsx", true);
			
			Map<String, Object> map = new HashMap<String, Object>();
			map.put("year", DateUtils.getYear());
			map.put("month", "7-9");
			map.put("list", objList);
			
			Workbook book = ExcelExportUtil.exportExcel(params, map);
			
			
			File savefile = new File("D:/excel/");
			if (!savefile.exists()) {
				savefile.mkdirs();
			}
			FileOutputStream fos = new FileOutputStream("D:/excel/emp.xls");
			book.write(fos);
			fos.close();

		} catch (Exception e) {
		}
	}

}
